# Maintainer: gym603 <gui_yuan_miao@163.com>

_realname=xlrd
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.2.0
pkgrel=1
pkgdesc="Library for developers to extract data from Microsoft Excel (tm) spreadsheet files (mingw-w64)"
arch=('any')
license=('custom')
url="https://github.com/python-excel/xlrd"
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/python-excel/xlrd/archive/${pkgver}.tar.gz)
sha256sums=('F3D25B39A9BDB273B4F13B2847F555EEF029983BDCD2B6283C81F4A93F45B827')

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1 --skip-build

  install -Dm644 docs/licenses.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/licenses.rst"

  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})
  for filename in runxlrd; do
    sed -e "s|${_mingw_prefix}/bin/|/usr/bin/env |g" -i "${pkgdir}${MINGW_PREFIX}"/bin/${filename}.py
  done
}
